import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import { storage } from '@/utils'
import getters from './getters'
import token from './modules/token'
import user from './modules/user'
import news from './modules/news'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    user,
    token,
    news,
  },
  getters,
  plugins: [
    createPersistedState({
      key: 'vuex',
      storage,
      paths: ['token', 'user'], // 持久化整个模块
    }),
  ],
})

export default store
